#include "login.h"
#include "ui_login.h"
#include"widget.h"
#include<QIcon>
#include<QToolButton>
#include<QList>
#include<QString>
#include<QStringList>
#include<QMessageBox>

Login::Login(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Login)
{
    ui->setupUi(this);
    //设置图标
    this->setWindowIcon(QIcon(":/icon/R-C.png"));
    //设置名称
    this->setWindowTitle("QQ 2024");

    QList<QString> nameList;
    nameList<<"提莫"<<"盲僧"<<"巨魔"<<"大头"<<"小丑"<<"泽拉斯"<<"石头人"<<"机器人"
             <<"筋肉亚索";
    QStringList iconNameList;//图标资源列表
    iconNameList<<"07"<<"a-xingbienanshitouxiang"<<"BARISTA"<<
        "icon-test"<<"icon-test_1"<<"peitubiaotouxiang-"<<
        "qiatongtouxiang"<<"touxiang-nv"<<"touxiangshangchuan-datouxiang";

    QVector<QToolButton *> vector;
    for(int i = 0;i < 9;i++){
        QToolButton *btn = new QToolButton(this);
        //加载图标
        btn->setIcon(QPixmap(QString(":/icon/%1.png").arg(iconNameList[i])));
        //设置图片大小
        btn->setIconSize(QPixmap(QString(":/icon/%1.png").arg(iconNameList[i])).size());
        //设置网名
        btn->setText(nameList[i]);
        //设置为透明
        btn->setAutoRaise(true);
        //设置显示格式
        btn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
        //放到vLayout布局中
        ui->vLayout->addWidget(btn);
        vector.push_back(btn);
        //窗口初始化态为false
        isShow.push_back(false);
    }
    for(int i = 0;i < 9;i++){
        connect(vector[i],&QToolButton::clicked,this,[=]{
            if(isShow[i]){
                QMessageBox::warning(this,"警告","该窗口已打开");
                return;
            }
            isShow[i] = !isShow[i];
            Widget *widget = new Widget(nullptr,vector[i]->text());
            widget->setWindowIcon(vector[i]->icon());
            widget->setWindowTitle(vector[i]->text());
            widget->show();

            //关闭窗口时，初始态重置
            connect(widget,&Widget::closeWidget,this,[=]{
                isShow[i] = !isShow[i];
            });
        });
    }
}

Login::~Login()
{
    delete ui;
}
